function cargarInterfazVariablesDeContrato(id_modelo)
{
	if(id_modelo)
	new Ajax.Updater({success:"div_variables_contrato",failure:'div_error'}, 'modelo/obtenerVariablesContrato?id='+id_modelo, {asynchronous:true, evalScripts:true, method:'GET' });
}




function mostrarInformacionTercero(valor, module)
{
	new Ajax.Updater({success:"div_mostrar_informacion_wincombo",failure:'div_error'}, module+'/obtenerInformacion?id='+valor, {asynchronous:true, evalScripts:true, method:'GET' });

}

function cargarTab(url, div)
{
    url = url+"";
    ocultarTabs();
    if(url.indexOf("index") > -1)
    {
     Element.show(div);
    }else
    {
	 Element.show(div);
     new Ajax.Updater({success:div,failure:'div_error'}, url+"?tabs=tabs", {asynchronous:true, evalScripts:true, method:'GET' });

    }
}
function ocultarTabs()
{
 divs = $$('div.div_tabs');
 divs.each(function(e)
 {
     Element.hide(e);
 });
 
}

function borrarSelect(id)
{
  
	var sel = $(id);
	var opt = sel.options;
	
	for(var i = opt.length - 1; i >= 0; i--)
	{
		opt[i] = null;
	}
  
}

function modificarDepartamentos(request)
{file:///datos/proyectos/billbravo-kernel/web/kernel/herramientas.js
    
    borrarSelect('departamento_selecionado');
    borrarSelect('ciudad_id');
    
    var cad = request.responseText;

    var sel = cad.split('--*--');

    var dep = sel[0].split('---');
    dp = $('departamento_selecionado');
    for(var i = 0; i < dep.length; i++)
    {
      spl = dep[i].split('###');
      if( String(spl[1]) != "undefined")
      {
        dp.options[i] = new Option(spl[1], spl[0]);
      }
      
    }

    var dep = sel[1].split('---');
    dp = $('ciudad_id');
    for(var i = 0; i < dep.length; i++)
    {
      spl = dep[i].split('###');
      if( String(spl[1]) != "undefined")
      {
        dp.options[i] = new Option(spl[1], spl[0]);
      }
      
    }


}

function modificarCiudades(request)
{
   
    borrarSelect('ciudad_id');
    var cad = request.responseText;
    var dep = cad.split('---');
    dp = $('ciudad_id');
    for(var i = 0; i < dep.length; i++)
    {
      spl = dep[i].split('###');
      if( String(spl[1]) != "undefined")
      {
        dp.options[i] = new Option(spl[1], spl[0]);
      }
      
    }
}

function cambiarValoresDepartamento(pais_id)
{
  new Ajax.Request('pais/getDepartamentos?id='+pais_id, {asynchronous:true, evalScripts:true, method:'GET', on200:function(request){ modificarDepartamentos(request)}});
  
}

function cambiarValoresCiudad(depto_id)
{
  new Ajax.Request('departamento/getCiudades?id='+depto_id, {asynchronous:true, evalScripts:true, method:'GET', on200:function(request){ modificarCiudades(request)}});
  
}




ker_windows = Array();
function crearVentanaAjax(id, url, options, atrib)
{

    if(atrib == null)
    {
        atrib = [];
        atrib['width'] = '600';
        atrib['height'] = '500';
    }
    id = 'win_'+id;
    //Dialog.alert({ url: url, options: options_request },{ id:"wincombo", hideEffect: Element.hide, className: "alphacube", width:540, height: 470, okLabel: "Cerrar", zIndex: 1000 });
    //atrib['draggable'] = true;
    ker_windows['win1'] = new Window(id, atrib);
   // ker_windows['win1'] = new Window('win_', { width:atrib['width'], height:atrib['height'], zIndex:1000, maximizable: false, resizable: true, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, destroyOnClose: true});
    ker_windows['win1'].setAjaxContent(url, options, true, false);
    ker_windows['win1'].setDestroyOnClose(true);
    myObserver = 
    { 
        onDestroy: function(eventName, win) 
        { 
            if (win == ker_windows['win1']) 
            { 
                //desbloquearVentana(); 
                ker_windows['win1'] = null; 
                Windows.removeObserver(this); 
            } 
        } 
    } 
    Windows.addObserver(myObserver); 
    return ker_windows['win1'];
}

/*
*  Quita los elementos de tipo checkbox seleccionados en un contenedor (id_objeto)
*  La funcion elimina los objectos  padres de los listados (tr) de la tabla donde esten los
*  checkbox.
*   @param string id_objeto, id del contenedor
*/
function borrarElementos(id_objeto)
{
	objeto = $(id_objeto);
	if (objeto)
	{
		elementos = objeto.length-1;
		removidos = 0;
		for (t=elementos; t>=0; t--)
		{	
			
			if ((objeto[t].type == 'checkbox' ) && (objeto[t].checked) )
			{
				try
				{
					Element.remove( $(objeto[t].id).parentNode.parentNode);
					removidos++;
				}catch(e){ alert(e);}
			}
		}
		restarNumeroResultados(removidos);

	}
}

function restarNumeroResultados(removidos)
{
	actuales = (+ $('div_result_list').innerHTML);
	$('div_result_list').innerHTML = actuales - removidos;
}

ponerModoConsulta = function (form_name)
{
    form = document.getElementById(form_name);

    detalles = $('div_detalles');
    if(detalles)
    {
      par = detalles.parentNode;
      par.removeChild(detalles);
    }

    del = document.getElementById('delete_button');
    if(del)
    {
      par = del.parentNode;
      par.removeChild(del);
    }
    res = document.getElementById('reset_button');
    if(res)
    {
      par = res.parentNode;
      par.removeChild(res);
    }

    
    var elements = new Array();
    if(form.tagName.toString().toLowerCase() == 'form') {
        var elements = form.getElementsByTagName('*');
    } else {
        elements[0] = form;
        while((form.tagName.toString().toLowerCase() != 'form') && (form.parentNode != null)) {
            form = form.parentNode;
        }
        if(form.tagName.toString().toLowerCase() != 'form') {
            elements = new Array();
        }
    }

    // Iterate through the form fields 
    for(var eCounter = 0; eCounter < elements.length; eCounter++) 
    {
        var element = elements[eCounter];
        if(element.type != "" && String(element.type) != "undefined" && String(element.type) != "submit"  && String(element.type) != "button"  && String(element.type) != "reset")
        {    

            element.value = '';
        }
    }

    
}


/*funciones para el maestro detalle*/
var contadorDetalle=0;
function generarDetalle(url,contador)
{ 

	    var indices = document.getElementsByName('indice[]');
        if(indices)
        {
	        contadorDetalle=indices.length;	
	    }
        else
            contadorDetalle++;

	  if(contadorDetalle==0)contadorDetalle++;

	 if($('div_detalles'))
	 {
        elem = $('div_detalles');
        var div = document.createElement("div");
        if($('detalle'+contadorDetalle))
        {
            contadorDetalle++;
        }        
        
        div.setAttribute("id", 'detalle'+(contadorDetalle));
        elem.appendChild(div);

     }
	o=new Ajax.Updater({success:'detalle'+contadorDetalle,failure:'error'}, url+'?contadorDetalle='+contadorDetalle, {asynchronous:true, evalScripts:true, method:'GET'});
    
	return false;
}

function modificarDetalle(url,contador)
{ 

    o=new Ajax.Updater({success:'detalle'+contador,failure:'error'}, url+'?contadorDetalle='+contadorDetalle, {asynchronous:true, evalScripts:true, method:'GET'});
    
    return false;
}

function reiniciarContador(url)
{
 contadorDetalle=0;	
 
}

function generarPdf(action, id)
{
//new Ajax.Request(action+'?id='+id, {asynchronous:true, evalScripts:false, method:'GET', on200:function(request){ alert('ok')}});
window.open(action+'?id='+id,  "ventana1", "width=120,height=300,scrollbars=NO");
}